#
# (C) 2009-10 - Luca Deri <deri@ntop.org>
#

obj-m := pf_ring.o

ifneq (, $(shell which svnversion))
SVNDEF := -DSVN_REV="\"$(shell svnversion -n .)\""
endif

ifeq (,$(BUILD_KERNEL))
BUILD_KERNEL=$(shell uname -r)
endif

EXTRA_CFLAGS += -I$(PWD) $(SVNDEF)

HERE=$(PWD)

# set the install path
INSTDIR := $(DESTDIR)/lib/modules/$(BUILD_KERNEL)/kernel/net/pf_ring
TARGETDIR := $(DESTDIR)/usr/src/$(BUILD_KERNEL)/include/linux/

all: Makefile pf_ring.c linux/pf_ring.h
	@if test "$(USER)" = "root"; then \
		echo "********** WARNING WARNING WARNING **********"; \
		echo "*"; \
		echo "* Compiling PF_RING as root might lead you to compile errors"; \
		echo "* Please compile PF_RING as unpriviliged user"; \
		echo "*"; \
		echo "*********************************************"; \
	fi
	make -C /lib/modules/$(BUILD_KERNEL)/build SUBDIRS=$(HERE) EXTRA_CFLAGS='$(EXTRA_CFLAGS)' modules
	cd plugins; make

clean:
	make -C /lib/modules/$(BUILD_KERNEL)/build SUBDIRS=$(HERE) clean
	\rm -f *~ Module.symvers  Module.markers  modules.order *#

install:
	mkdir -p $(INSTDIR)
	cp *.ko $(INSTDIR)
	cp linux/pf_ring.h $(DESTDIR)/usr/include/linux
	@if test -d ${TARGETDIR}; then \
		cp linux/pf_ring.h ${TARGETDIR}; \
	fi
ifeq (,$(DESTDIR))
	/sbin/depmod $(BUILD_KERNEL)
endif
